import { useStorage } from "@vueuse/core";
import { defineStore } from "pinia";
import { ref } from "vue";

export const useAppStore = defineStore("app", () => {
  /**
   * 侧边栏是否打开
   */
  const sidebarOpened = ref<Boolean>(true);

  /**
   * 切换侧边栏状态
   */
  function toggleSidebarOpened() {
    sidebarOpened.value = !sidebarOpened.value;
  }

  /**
   * 国际化语言
   */
  const language = useStorage("language", "zh");

  /**
   * 设置语言
   * @param lang
   */
  function setLanguage(lang: string) {
    language.value = lang;
  }

  return { sidebarOpened, toggleSidebarOpened, language, setLanguage };
});
